package net.lzzy.practices.web.models;

import lombok.Getter;
import lombok.Setter;
import net.lzzy.practices.entities.Question;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

/**
 * @author liaodcc on 2022/6/1 17:01.
 */
@Getter
@Setter
public class VmQuestion {
    private UUID id;
    private int type;
    private String content;
    private String analysis;
    private int ordinal;
    private UUID chapterId;
    private String chapterName;
    private List<VmOption> options = new ArrayList<>();

    private VmQuestion(){}

    public static VmQuestion create(Question question,boolean teacher){
        VmQuestion vm = new VmQuestion();
        vm.setId(question.getId());
        vm.setAnalysis(question.getAnalysis());
        vm.setChapterId(question.getChapter().getId());
        vm.setChapterName(question.getChapter().getName());
        vm.setContent(question.getContent());
        vm.setOrdinal(question.getOrdinal());
        vm.setType(question.getType());
        List<VmOption> options = new ArrayList<>();
        question.getOptions().forEach(option -> options.add(VmOption.create(option,teacher)));
        vm.setOptions(options);
        return vm;
    }
}
